<?php 
header("content-type:text/html;charset=utf-8");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=lx","root","root");
$sql = "select * from goods";
$res = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);

 ?>
 <!DOCTYPE html>
 <html>
 <head>
 	<title>展示界面</title>
 </head>
 <body>
 <center>
 	<table border="1">
 		<tr>
 			<td>ID</td>
 			<td>商品名称</td>
 			<td>商品数量</td>
 			<td>原价</td>
 			<td>惊爆价</td>
 			<td>开始剩余时间</td>
 			<td>操作</td>
 		</tr>
 		<?php foreach ($res as $key => $value){ ?>
 			<tbody>
 				<tr>
 					<td><?php echo $value['id']; ?></td>
 					<td><?php echo $value['name']; ?></td>
 					<td><?php echo $value['count']; ?></td>
 					<td><?php echo $value['yprice']; ?></td>
 					<td><?php echo $value['jprice']; ?></td>
 					<td>倒计时:<span id="hour"></span><span id="min"></span><span id="sec"></span></td>
 					<td><input type="button" data-id="" id="<?php echo $value['id']; ?>" class="" value="抢购" onclick="dl(id)"></td>
 				</tr>
 			</tbody>
 		<?php } ?>
 		
 	</table>
 </center>
 </body>
 </html>
 <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
 <script type="text/javascript">
 	window.setInterval(function(){
 		$.getJSON('time.php',function(e){
 			$("#hour").html(e.hour+"时");
 			$("#min").html(e.min+"分");
 			$("#sec").html(e.sec+"秒");
 		});
 	},1000);
 	function dl(goods_id){
 		alert(goods_id);
 		$.ajax({
 			url:"qg.php",
 			data:{goods_id:goods_id},
 			dataType:"json",
 			type:"post",
 			success:function(res){
 				alert(res.msg);
 				location.href="show.php";
 			}
 		})
 	}
 </script>